# -*- encoding=utf8 -*-
"""
RedFlag-TC0000106  （拍摄进入装饰页）编辑文字功能
新增文字场景
编辑文字场景
设置文字时长场景
删除文字场景
"""
__author__ = "ldm"

import sys
import os

# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *

auto_setup(__file__)
shooter = CameraVideoShooter()

case_text = "这是一条测试数据"
case_Text = "测试编辑文字功能"

log("--------------------------------新增文字场景--------------------------------------")
"""
拍摄视频进入装饰页
等待
截图（用于后续场景文字时间做断言比对）
点击文字
输入指定的文案
使用一个字体
点击颜色
使用一个颜色
点击气泡
使用一个气泡
点击保存
断言
"""

shooter.enter_photography_decoration_page()
sleep(1.0)
photo1 = shooter.capture_screenshot("TC0000106A.png")
shooter.click_element(decoration_page_text_function)
shooter.input_text_in_element(decoration_page_text_function_input, case_text)
shooter.click_element(decoration_page_text_function_font[1])
shooter.click_element(decoration_page_text_function_colour)
shooter.click_element(decoration_page_text_function_choice_colour[1])
shooter.click_element(decoration_page_text_function_bubble)
shooter.click_element(decoration_page_text_function_choice_bubble[1])
shooter.click_element(decoration_page_text_function_confirm)
shooter.assert_image_exists(r"tpl1748509284797.png", "断言失败，未发现预期图片", record_pos=(0.006, -0.06), resolution=(1224, 2700))

log("--------------------------------编辑文字场景--------------------------------------")
"""
点击文字
点击编辑
重新输入文案
使用第二个字体
点击颜色
使用第二个颜色
点击气泡
使用第二个气泡
点击保存
断言
"""
touch((0.5,0.46))
shooter.click_element(decoration_page_text_editing_edit)
shooter.click_element(decoration_page_text_function_delete)
shooter.input_text_in_element(decoration_page_text_function_input, case_Text)
shooter.click_element(decoration_page_text_function_font[2])
shooter.click_element(decoration_page_text_function_colour)
shooter.click_element(decoration_page_text_function_choice_colour[2])
shooter.click_element(decoration_page_text_function_bubble)
shooter.click_element(decoration_page_text_function_choice_bubble[2])
shooter.click_element(decoration_page_text_function_confirm)
shooter.assert_image_exists(r"tpl1748509695578.png", "断言失败，未发现预期图片", record_pos=(-0.011, -0.005), resolution=(1224, 2700), threshold=0.90)

log("--------------------------------设置文字时长场景--------------------------------------")
"""
点击文字
点击设置时长
拖动按钮设置动画时长
点击取消
点击文字
点击设置时长
断言
拖动按钮设置动画时长
点击确认
点击文字
点击设置时长
断言
点击确认
截图
断言
断言
"""

touch((0.5,0.46))
shooter.click_element(decoration_page_text_editing_time)
shooter.swipe_screen((0.105,0.8), (0.35,0.8))
shooter.click_element(decoration_page_text_editing_time_cancel)
touch((0.5,0.46))
shooter.click_element(decoration_page_text_editing_time)
shooter.assert_image_exists(r"tpl1748522178478.png", "断言失败，预期图片不存在", record_pos=(-0.001, 0.661), resolution=(1224, 2700),threshold=0.9)
shooter.swipe_screen((0.105,0.8), (0.35,0.8))
shooter.click_element(decoration_page_text_editing_time_confirm)
touch((0.5,0.46))
shooter.click_element(decoration_page_text_editing_time)
shooter.assert_image_not_exists(r"tpl1748522178478.png", "断言失败，预期图片存在", record_pos=(-0.001, 0.661), resolution=(1224, 2700),threshold=0.9)
shooter.click_element(decoration_page_text_editing_time_confirm)
photo2 = shooter.capture_screenshot("TC0000106B.png")
shooter.assert_images_equal(photo1,photo2,"断言失败，图片比对不一致",threshold=0.95)
shooter.assert_image_exists(r"tpl1748509695578.png","断言失败，未发现预期图片", record_pos=(-0.011, -0.005), resolution=(1224, 2700), threshold=0.9)

log("--------------------------------删除文字场景--------------------------------------")
"""
点击文字
点击删除
断言
"""

touch((0.5,0.48))
shooter.click_element(decoration_page_text_editing_delete)
shooter.assert_image_not_exists(r"tpl1748509695578.png", "断言失败，发现预期图片", record_pos=(-0.011, -0.005), resolution=(1224, 2700), threshold=0.9)

# 关闭应用
stop_app(UGC_package_name)